home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / plan / plan_cal.ps < prev    next >
Text File  |  1994-08-01  |  9KB  |  405 lines

  1. /DefNormFont /Helvetica         findfont def
  2. /DefBoldFont /Helvetica-Bold    findfont def
  3. /DefItalFont /Helvetica-Oblique findfont def
  4.  
  5. /TopMarginOfs    10 def
  6. /BottomMarginOfs 20 def
  7. /LeftMarginOfs   20 def
  8. /RightMarginOfs  20 def
  9.  
  10. /Months [ ()
  11.   (January) (February) (March) (April)
  12.   (May) (June) (July) (August)
  13.   (September) (October) (November) (December)
  14. ] def
  15.  
  16. /WeekDays [ ()
  17.   (Sun) (Mon) (Tue) (Wed) (Thu) (Fri) (Sat) (Sun)
  18. ] def
  19.  
  20. /Days [ 0
  21.   31 28 31 30 31 30 31 31 30 31 30 31
  22. ] def
  23.  
  24. /Debug { pop } bind def
  25. /DebugValue { pop pop } bind def
  26. % /DebugBuf 256 string def
  27. % /Debug { print flush } bind def
  28. % /DebugValue { exch print DebugBuf cvs print (\n) print flush } def
  29.  
  30. /PosDict 400 dict def
  31. /CalDicts 10 dict def
  32.  
  33. /Register { % Name Size
  34.   dict
  35.   % Name dict
  36.   exch
  37.   % dict Name
  38.   CalDicts
  39.   % dict Name CalDicts
  40.   exch
  41.   % dict CalDicts Name
  42.   2 index put
  43. } def
  44.  
  45. % Common Functions
  46. /_Mark {
  47.   gsave
  48.     36 dup scale
  49.     0.0 setlinewidth
  50.     -1 0 rmoveto 2 0 rlineto -1 -1 rmoveto 0 2 rlineto stroke
  51.   grestore
  52. } def
  53. /Mark {
  54.   gsave
  55.    _Mark
  56.    45 rotate 0.75 dup scale _Mark
  57.    22.5 rotate 0.75 dup scale _Mark 45 rotate _Mark
  58.   grestore
  59. } def
  60. /FontTopBot { % font -> TopYoffset BottomYoffset
  61.     dup /FontBBox get aload pop 5 -1 roll /FontMatrix get dup
  62.     4 1 roll dtransform exch pop 4 1 roll dtransform exch pop
  63. } def
  64. /box {
  65.     4 copy
  66.     moveto
  67.     exch 3 -1 roll lineto
  68.     4 -2 roll lineto lineto
  69.     closepath
  70. } def
  71.  
  72. /rbox { % from currentpoint: Xsize Ysize
  73.     currentpoint
  74.     % Xsize Ysize X1 Y1
  75.     currentpoint 
  76.     % Xsize Ysize X1 Y1 x2 y2
  77.     exch 6 -1 roll
  78.     % Ysize X1 Y1 y2 x2 Xsize
  79.     add
  80.     % Ysize X1 Y1 y2 X2
  81.     exch 5 -1 roll
  82.     % X1 Y1 X2 y2 Ysize
  83.     add
  84.     % X1 Y1 X2 Y2
  85.     box
  86. } bind def
  87.  
  88. /Landscape {
  89.   % Auto Rotate Page to Landscape
  90.   newpath clippath pathbbox % llx lly urx ury
  91.   pop exch pop exch % DevWidth
  92.   add 0 translate 90 rotate
  93. } bind def
  94.  
  95. /SetMinMax {
  96.   % Set MinX, MaxX, MinY MaxY from clippath
  97.   newpath clippath pathbbox newpath % llx lly urx ury
  98.   transform round 1 add exch round 1 sub exch itransform
  99.   /MaxY exch def /MaxX exch def
  100.   transform round 1 sub exch round 1 add exch itransform
  101.   /MinY exch def /MinX exch def
  102.  
  103.   % Fudge factor..
  104.   /MinX MinX 2 add LeftMarginOfs   add def
  105.   /MaxX MaxX 2 sub RightMarginOfs  sub def
  106.   /MinY MinY 2 add BottomMarginOfs add def
  107.   /MaxY MaxY 2 sub TopMarginOfs    sub def
  108. } def
  109.  
  110. /CurY { currentpoint exch pop } bind def
  111. /CurX { currentpoint pop } bind def
  112.  
  113. /CenterShow {
  114.   dup stringwidth pop -2 div 0 rmoveto show
  115. } bind def
  116.  
  117. /AdjWeekDay {
  118.   SundayFirst not {
  119.     1 sub dup 0 lt { pop 6 } if
  120.   } if
  121. } bind def
  122.  
  123. % Define 'Year' Print Functions
  124. /Year 50 Register begin
  125.   /MonthNameFont    DefItalFont    11 scalefont def
  126.   /MonthWeekDayFont    DefNormFont     7 scalefont def
  127.   /MonthWeekNumFont    DefBoldFont     7 scalefont def
  128.   /EntryFont        DefBoldFont     3 scalefont def
  129.   /HolidayFont        DefItalFont     3 scalefont def
  130.  
  131.   /MonthXofs  9 def
  132.   /MonthYofs 12 def
  133.  
  134.   /Init {
  135.     (Year: Init...\n) Debug
  136.     Landscape
  137.   } def
  138.  
  139.   /Start {
  140.     % Put month dict onto stack under our own dict.
  141.     currentdict end CalDicts /Month get begin begin
  142.  
  143.     (Year: Start...\n) Debug
  144.  
  145.     % Somewhere we can paint junk...
  146.     MaxX MaxY moveto 8 dup rmoveto 
  147.     /undef PosDict exch [ currentpoint matrix currentmatrix 0 ] put
  148.  
  149.     DefBoldFont 18 scalefont setfont
  150.     MinX MaxX MinX sub 2 div add MaxY moveto
  151.     0 currentfont FontTopBot sub neg rmoveto
  152.     Year 6 string cvs CenterShow
  153.     MinX currentpoint exch pop moveto
  154.  
  155.     MonthXofs -9 rmoveto
  156.  
  157.     /MonthWidth  MaxX MinX sub 5 MonthXofs mul sub 4 div def
  158.     /MonthHeight CurY MinY sub 3 MonthYofs mul sub 3 div def
  159.     /MonthRowHeight MonthHeight MonthYofs add def
  160.     /DayWidth  MonthWidth  7 div def
  161.  
  162.     1 1 12 {
  163.       gsave
  164.     gsave 0 MonthRowHeight neg rmoveto currentpoint grestore translate
  165.     dup PaintMonth
  166.     /WeekDay WeekDay SundayFirst not { 1 add 7 mod } if def
  167.       grestore
  168.       MonthWidth MonthXofs add 0 rmoveto
  169.       4 mod 0 eq {
  170.     MinX currentpoint exch pop moveto
  171.     MonthXofs MonthRowHeight neg rmoveto
  172.       } if
  173.     } for
  174.   } def
  175.   /Finish {
  176.     (Year: Finish...\n) Debug
  177.     showpage
  178.   } def
  179. end
  180.  
  181. % Define 'Month' Print Functions
  182. /Month 50 Register begin
  183.   /MonthNameFont    DefBoldFont 20 scalefont def
  184.   /MonthWeekDayFont    DefNormFont 12 scalefont def
  185.   /MonthWeekNumFont    DefBoldFont 16 scalefont def
  186.   /EntryFont        DefBoldFont  9 scalefont def
  187.   /HolidayFont        DefItalFont  9 scalefont def
  188.  
  189.   /Init {
  190.     (Month: Init...\n) Debug
  191.     Landscape
  192.   } def
  193.   /Start {
  194.     (Month: Start...\n) Debug
  195.  
  196.     % Somewhere we can paint junk...
  197.     MaxX MaxY moveto 8 dup rmoveto 
  198.     /undef PosDict exch [ currentpoint matrix currentmatrix 0 ] put
  199.  
  200.     %
  201.     /MonthWidth MaxX MinX sub 4 sub def
  202.     MinX MinY translate
  203.     0 MaxY MinY sub moveto
  204.     Month PaintMonth
  205.     gsave
  206.   } def
  207.   /PaintMonth {
  208.     /CurMonth exch def
  209.     (PaintMonth: CurMonth = ) CurMonth DebugValue
  210.  
  211.     MonthNameFont setfont
  212.    
  213.     Print_Mode (Month) ne {
  214.       0 currentfont FontTopBot sub neg rmoveto
  215.       Months CurMonth get show
  216.       0 -6 rmoveto
  217.     } {
  218.       MonthWidth 2 div currentfont FontTopBot sub neg rmoveto
  219.  
  220.       Year 6 string cvs dup stringwidth pop -2 div 0 rmoveto
  221.         Months CurMonth get dup stringwidth pop -2 div 0 rmoveto
  222.         (  ) stringwidth pop -2 div 0 rmoveto
  223.         show (  ) show show
  224.  
  225.       0 -9 rmoveto
  226.     } ifelse
  227.  
  228.     0 currentpoint exch pop moveto
  229.  
  230.     /MonthHeight CurY 2 sub def
  231.     /DayWidth MonthWidth 7 div def
  232.  
  233.     gsave
  234.       0.48 setlinewidth
  235.  
  236.       MonthWeekDayFont setfont
  237.       0 currentfont FontTopBot /YO exch def neg rmoveto
  238.       gsave
  239.     SundayFirst { /D 0 def } { /D 1 def } ifelse
  240.     7 {
  241.       D 1 add WeekDays exch get
  242.       gsave 3 2 rmoveto show grestore
  243.       DayWidth 0 rmoveto
  244.       /D D 1 add 7 mod def
  245.     } repeat
  246.       grestore
  247.       0 YO rmoveto
  248.  
  249.       /DayHeight CurY 6 div def
  250.  
  251.       MonthWeekNumFont setfont
  252.       /StartWeekDay WeekDay def
  253.       gsave
  254.     0 currentfont FontTopBot /YO exch def neg /YYO exch def YYO rmoveto
  255.     /YYMM Year 1900 sub 10000 mul CurMonth 100 mul add def
  256.     /CurWeek 0 def
  257.     /DayStr 2 string def
  258.     /WeekDay WeekDay AdjWeekDay def
  259.     2 WeekDay DayWidth mul add 0 rmoveto
  260.  
  261.     /DayNumYofs YYO def
  262.  
  263.     1 1
  264.     Days CurMonth get
  265.       CurMonth 2 eq Year 4 mod 0 eq and { pop 29 } if
  266.     {
  267.       /CurDay exch def
  268.  
  269.       CurDay DayStr cvs
  270.       gsave
  271.         CurX exch show CurX exch sub /DX exch def
  272.       grestore
  273.  
  274.       % Save position info for later use...
  275.       gsave
  276.         -2 YYO neg rmoveto
  277.         YYMM CurDay add 6 string cvs cvn
  278.         PosDict exch [ currentpoint matrix currentmatrix DX ] put
  279.       grestore
  280.  
  281.       /WeekDay WeekDay 1 add 7 mod def
  282.  
  283.       WeekDay 0 eq {
  284.         /CurWeek CurWeek 1 add def
  285.         0 2 add currentpoint exch pop DayHeight sub moveto
  286.       } {
  287.         DayWidth 0 rmoveto
  288.       } ifelse
  289.     } for
  290.       grestore
  291.  
  292.       % Paint Gray Squares
  293.       gsave
  294.     StartWeekDay AdjWeekDay {
  295.       gsave
  296.         0.98 setgray
  297.         DayWidth DayHeight neg rbox fill
  298.       grestore
  299.       DayWidth 0 rmoveto
  300.     } repeat
  301.       grestore
  302.  
  303.       /W WeekDay def
  304.       CurWeek 1 5 {
  305.     /CurWeek exch def
  306.     gsave
  307.       W DayWidth mul CurWeek DayHeight mul neg rmoveto
  308.       % Gray remaining boxes...
  309.       7 W sub {
  310.         gsave
  311.           0.98 setgray
  312.           DayWidth DayHeight neg rbox fill
  313.         grestore
  314.         DayWidth 0 rmoveto
  315.       } repeat
  316.     grestore
  317.     /W 0 def
  318.       } for
  319.  
  320.       % Paint Grid...
  321.       gsave
  322.     6 {
  323.       DayWidth 0 rmoveto
  324.       gsave CurX 0 lineto stroke grestore
  325.     } repeat
  326.       grestore
  327.       gsave
  328.     5 {
  329.       0 DayHeight neg rmoveto
  330.       gsave MonthWidth CurY lineto stroke grestore
  331.     } repeat
  332.       grestore
  333.  
  334.       % Paint outside box
  335.       gsave
  336.     1.44 setlinewidth
  337.     MonthWidth CurY 0 0 box stroke
  338.       grestore
  339.     grestore
  340.   } def
  341.   /Finish {
  342.     (Month: Finish...\n) Debug
  343.     grestore
  344.     showpage
  345.   } def
  346.   /NewDay {
  347.     [ /CurJul /CurWeek /CurYear /CurDay /CurMonth ] { exch def } forall
  348.  
  349.     grestore
  350.     gsave
  351.       CurYear 10000 mul CurMonth 100 mul add CurDay add 10 string cvs cvn
  352.       PosDict exch 2 copy known not { pop /undef } if
  353.       get aload pop /DayNumXofs exch def setmatrix moveto
  354.  
  355.       EntryFont setfont
  356.       /YO currentfont FontTopBot sub neg def
  357.  
  358.       currentpoint 
  359.         DayWidth 1 sub DayHeight 1 sub neg rbox clip
  360.       moveto
  361.  
  362.       2 DayNumYofs rmoveto
  363.   } def
  364.   /PaintHolidays {
  365.     DayNumXofs 0 rmoveto
  366.     /Z DayNumXofs neg def
  367.     /F currentfont def
  368.     HolidayFont setfont
  369.     {
  370.       gsave (  ) show show grestore
  371.       Z YO rmoveto
  372.       /Z 0 def
  373.     } forall
  374.     Z YO neg rmoveto
  375.     F setfont
  376.   } def
  377.   /PaintEntry {
  378.     [ /Entry_Message /Entry_Note /Entry_Time /Entry_Date ] { exch def } forall
  379.  
  380.     0 YO rmoveto
  381.     gsave
  382.       % Entry_Date show ( ) show
  383.       Entry_Time () ne { Entry_Time show ( ) show } if
  384.       Entry_Note show
  385.     grestore
  386.   } def
  387. end
  388.  
  389. % Functions Common to all Calendars...
  390. /InitCal {
  391.   % Make "Current Print Mode" Functions availble on Dict Stack...
  392.   CalDicts Print_Mode cvn get begin
  393.  
  394.   Init
  395.  
  396.   SetMinMax
  397.  
  398.   Start
  399. } def
  400.  
  401. /FinishCal {
  402.   Finish
  403.   end
  404. } def
  405.